<?php
class VideoreplyApp extends BackendApp
{
	var $_videoreply_mod;
    var $_video_mod;

	function __construct()
	{
		$this->VideoreplyApp();
	}

	function VideoreplyApp()
	{
		parent::BackendApp();

		$this->_videoreply_mod =& m('videoreply');
        $this->_video_mod = & m('video');
	}

	function index()
	{

		$conditions = '';
		$conditions .= $this->_get_query_conditions(array(
            array(
                'field' => 'cv.content',         //可搜索字段title
                'equal' => 'LIKE',          //等价关系,可以是LIKE, =, <, >, <>
                'assoc' => 'AND',           //关系类型,可以是AND, OR
                'name'  => 'content',         //GET的值的访问键名
                'type'  => 'string',        //GET的值的类型
            ),array(
                'field' => 'cr.replydate',
                'name'  => 'add_time_from',
                'equal' => '>=',
                'handler'=> 'gmstr2time',
            ),array(
                'field' => 'cr.replydate',
                'name'  => 'add_time_to',
                'equal' => '<=',
                'handler'   => 'gmstr2time_end',
            ),
		));

		$page   =   $this->_get_page(10);   //获取分页信息
		$sql_count = "SELECT COUNT(1) FROM cw_videoreply AS cr
                    LEFT JOIN cw_video AS cv ON cv.video_id = cr.video_id
					LEFT JOIN cw_member AS cm ON cr.uid = cm.user_id
					WHERE 1=1 ".$conditions." ORDER BY cr.replydate DESC";
		$res_count = $this->_videoreply_mod->getOne($sql_count);

        $sql = "SELECT cr.reply_id,cr.replydate,cr.content as contents,cm.user_name,cm.real_name,cv.content,cv.video_id FROM cw_videoreply AS cr
                    LEFT JOIN cw_video AS cv ON cv.video_id = cr.video_id
					LEFT JOIN cw_member AS cm ON cr.uid = cm.user_id
					WHERE 1=1 ".$conditions." ORDER BY cr.replydate DESC LIMIT ".$page['limit'];
        $videoreplys = $this->_videoreply_mod->getAll($sql);
        $page['item_count']=$res_count;   //获取统计数据
        $this->_format_page($page);
        $this->assign('page_info', $page);   //将分页信息传递给视图，用于形成分页条
        /*
        $this->assign('checked', $checked); //分类树
        */

        $this->assign('filtered', $conditions? 1 : 0); //是否有查询条件
        $this->import_resource(array('script' => 'inline_edit.js,jquery.ui/jquery.ui.js,jquery.ui/i18n/' . i18n_code() . '.js',
            'style'=> 'jquery.ui/themes/ui-lightness/jquery.ui.css'));
        $this->assign('videoreplys',$videoreplys);
		$this->display('videoreply.index.html');
	}
	function view(){
		$id     = empty($_GET['id']) ? 0 : intval($_GET['id']);
		if(!$id){
			$this->show_warning('没有改视频记录！');
			return;
		}
		$sql = 'SELECT file_path FROM cw_video WHERE video_id ='.$id;
		$videoreply = $this->_video_mod->getRow($sql);
		if(!$videoreply){
			$this->show_warning('该视频不存在！');
			return;
		}
		$this->assign('videoreply',$videoreply);
		$this->display('videoreply.video.html');
	}
    /* 删除 */
    function drop()
    {
        $id = isset($_GET['id']) ? trim($_GET['id']) : '';
        if (!$id)
        {
            $this->show_warning('no_region_to_drop');
            return;
        }

        $ids = explode(',', $id);
        if (!$this->_videoreply_mod->drop($ids))
        {
            $this->show_warning($this->_videoreply_mod->get_error());
            return;
        }

        $this->show_message('drop_ok');
    }
}